;**********************************************
; Macroses for global variables handling.
; This macro library is part of Fresh project.
;
; (C)2003, 2004
;
; Authors:
;   John Found
;   Tomasz Grisztar
;
; usage:
;   1. Include this library in the begining
;      of your source file.
;   2. Use it as blocks anywhere in the source.
;        iglobal
;           somelabel dd 1234h
;           otherlabel RECT
;           lbl3       db 12h
;        endg
;
;   3. Data section must be at the end of the
;      source file. Use 'IncludeAllGlobals' to
;      really define variables.
;
;**********************************************

;------------------------------------------------------------------
; use "iglobal" for inserting initialized global data definitions.
;------------------------------------------------------------------
macro iglobal {
  IncludeIGlobals fix IncludeIGlobals,
  macro __IGlobalBlock {
}

;-------------------------------------------------------------
; use 'uglobal' for inserting uninitialized global definitions.
; even when you define some data values, these variables
; will be stored as uninitialized data.
;-------------------------------------------------------------
macro uglobal {
  IncludeUGlobals fix IncludeUGlobals,
  macro __UGlobalBlock {
}

endg fix }      ; Use endg for ending iglobal and uglobal blocks.

macro __IncludeIGlobals dummy,[n]
{
  forward
   __IGlobalBlock
   purge __IGlobalBlock
}

macro __IncludeUGlobals dummy,[n]
{
  common
    local begin, size
    begin = $
    virtual at $
  forward
      __UGlobalBlock
      purge __UGlobalBlock
  common
      size = $ - begin
    end virtual
    rb size
}



;--------------------------------------------
; Use this macro to define non duplicated
; string constants.
;
; constStr Str1, 'This is string constant'
;--------------------------------------------
macro  constStr  lbl, text {
  __StringsArray fix __StringsArray, lbl, text     ;;  add to the list
}


macro __IncludeStringConstants dummy, [lbls, text] {
  forward
    if text eqtype 'A'
      lbls db text
      sizeof.#lbls = $ - lbls
      db 0
    else
      if text eqtype 0
        lbls = text
      end if
    end if
}

macro IncludeStringConstants {
  __IncludeStringConstants __StringsArray
}


macro IncludeAllGlobals {
  local begin

  begin = $
  IncludeIGlobals
  DispSize 'Initialized data', ($ - begin)

  begin = $
  IncludeStringConstants
  DispSize 'String constants data', ($ - begin)

  begin = $
  IncludeUGlobals
  DispSize 'Uninitialized data', ($ - begin)
}

IncludeIGlobals fix __IncludeIGlobals
IncludeUGlobals fix __IncludeUGlobals

iglobal
endg

uglobal
endg

